package com.unknowpupil.sell.config.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MetaObjectHandlerConfig implements MetaObjectHandler {
  private static final Logger logger = LoggerFactory.getLogger(MetaObjectHandlerConfig  .class);

  @Override
  public void insertFill(MetaObject metaObject) {
//    SysUserEntity userEntity = ShiroUtil.getUser();
//    this.setFieldValByName("createTime", new Date(), metaObject);
//    this.setFieldValByName("createBy", userEntity.getLoginName(), metaObject);
//    this.setFieldValByName("updateTime", new Date(), metaObject);
//    this.setFieldValByName("updateBy", userEntity.getLoginName(), metaObject);

    System.out.println("插入方法实体填充");
    setFieldValByName("created", new Date(), metaObject);
    setFieldValByName("updated", new Date(), metaObject);
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    System.out.println("更新方法实体填充");
//    SysUserEntity userEntity = ShiroUtil.getUser();
//   this.setFieldValByName("updateBy", userEntity.getLoginName(), metaObject);
    this.setFieldValByName("updated", new Date(), metaObject);
  }
}
